package thread.communication;
import static java.lang.System.out;

public class Waiting {
	static int[] array = new int[30];
	volatile static boolean isFilled = false;

	public static void main(String[] args) {
		
		
		Runnable runnable = new Runnable() {
			@Override
		    public void run() {
				synchronized (array) {
					for (int j = 0; j < 30; j++) {
						array[j] = j;
					}
					array.notify();											
				}
				
				// Set the flag, when Job is completed.
				isFilled = true;
		    }
		};
		
		Thread t = new Thread(runnable);
		
		t.start();
		synchronized (array) {
			try {
				do{
					array.wait();						
					
				}while(!isFilled);
			} catch (InterruptedException e) {
				out.println(e.toString());
			}
		}
		
		print();
		
	}
	
	static void print() {
		for (int i : array) {
			out.print(i + ",");
		}
		out.print("\n");
	}
}

// 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
